package com.zzy.mccjt.core.config;

import com.zzy.mccjt.core.interceptor.BRequestInterceptor;
import com.zzy.mccjt.core.interceptor.CRequestInterceptor;
import com.zzy.mccjt.core.interceptor.InnerRequestInterceptor;
import com.zzy.mccjt.core.interceptor.OpenApiRequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

/**
 * @program: mccjt-cloud
 * @description:
 * @author: zhouyang.zheng
 * @create: 2022-08-04 10:29
 **/
@Configuration
@ConditionalOnMissingBean(name = "customWebConfiguration")
public class WebConfiguration implements WebMvcConfigurer {

    /**
     * 将 /api/ 下所有接口进行请求拦截，非此前缀下默认有通过权限
     *
     * @param registry 拦截注册器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new InnerRequestInterceptor()).addPathPatterns("/inner/**");
        registry.addInterceptor(new BRequestInterceptor()).addPathPatterns("/b/**");
        registry.addInterceptor(new CRequestInterceptor()).addPathPatterns("/c/**");
        registry.addInterceptor(new OpenApiRequestInterceptor()).addPathPatterns("/open/**");

        //国际化支持
        registry.addInterceptor(new LocaleChangeInterceptor());
    }
}

